package semanticAbstraction;

import semanticAbstraction.interfaces.SemanticHandler;
import semanticAbstraction.wsmxAdapter.WSMX_SemanticHandler;

import core.exceptions.UnknownSemanticLanguageException;

/**
 * Class that provides possibility to create a proper {@ link SemanticHandler} instance for the used
 * document language.
 * 
 * @author Christian Stamber
 *
 */
public class SemanticHandlerFactory {
	
	private static SemanticHandler semanticHandler;
	
	/**
	 * Selects dependent on the the semantic language of the {@link semanticDecription} the proper
	 * {@link SemanticHandlerFactory}. If a unknown semantic language is discovered, an {@link UnknownSemanticLanguageException} is thrown.
	 * @param semanticDescription
	 * @return {@link SemanticHandlerFactory} (e.g. {@link WSMX_SemanticFactory}) that matches the language of the semanticDescription
	 * @throws UnknownSemanticLanguageException
	 */
	public static SemanticHandler createSemanticHandler(String semanticDocument)/* throws UnknownSemanticLanguageException*/{
		
		// every wsml file (should) contain "wsmlVariant"
		if(semanticDocument.contains("wsmlVariant") || semanticDocument.contains("ontology")){
			if(semanticHandler==null){
				if(!(semanticHandler instanceof WSMX_SemanticHandler)){
					semanticHandler=new WSMX_SemanticHandler();
				}
			}
		}else{
			//throw new UnknownSemanticLanguageException();
		}
		return semanticHandler;
	}
}
